package vip.xiaonuo.modular.manage.tsdatarecord.parser;

import cn.hutool.core.map.MapUtil;
import cn.hutool.extra.spring.SpringUtil;

import java.util.Map;
import java.util.Optional;

/**
 * FileParserSupport
 *
 * @author JackLee
 * 2022/8/5 16:03
 */
public class FileParserSupport {

    public static FileParser getParser(String type) {
        Map<String, FileParser> parserMap = SpringUtil.getBeansOfType(FileParser.class);
        if (MapUtil.isEmpty(parserMap)) {
            return null;
        }
        Optional<FileParser> parserOptional = parserMap.values().stream().filter(fp -> fp.available(type)).findFirst();
        return parserOptional.orElse(null);
    }
}
